home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -serious- / hardware / blizkick / modules / blizkickmodule.i < prev    next >
Text File  |  1999-05-17  |  8KB  |  299 lines

  1.     IFND    BLIZKICKMODULE_I
  2. BLIZKICKMODULE_I    SET    1
  3. **
  4. **    $VER: blizkickmodule.i 1.3 (10.4.97)
  5. **    Includes Release 1.3
  6. **
  7. **    Macros and defines for BlizKick's "modules" and "patches".
  8. **
  9. **    (C) Copyright 1996-1997 PitPlane Productions.
  10. **        All Rights Reserved
  11. **
  12.  
  13.     IFND EXEC_TYPES_I
  14.     INCLUDE "exec/types.i"
  15.     ENDC ; EXEC_TYPES_I
  16.  
  17.     IFND EXEC_NODES_I
  18.     INCLUDE "exec/nodes.i"
  19.     ENDC ; EXEC_NODES_I
  20.  
  21.     IFND EXEC_RESIDENT_I
  22.     INCLUDE "exec/resident.i"
  23.     ENDC ; EXEC_RESIDENT_I
  24.  
  25.     IFGT    0
  26.  
  27.    "Modules" are executable files that are loaded with LoadSeg(). Only the
  28.  first segment can be used and the code *MUST* be PC-relative. Modules contain
  29.  a LONG id and Resident Tag. This resident tag will be added to KS ROM. There
  30.  are two macros defined in this file (BK_MOD and BK_MODA), which can be used
  31.  (=should be used) to create "Modules".
  32.  
  33.    "Module" can (from BlizKick V1.6 on) also be a patch, in which case macro
  34.  called BK_PTC should be used to create it. See macro definition below for
  35.  detailed information. Note that "patch" needn't be fully PC-relative (the
  36.  patching code can be relocatable, it is loaded with LoadSeg() after all).
  37.  
  38.  
  39.  bkm_Flags
  40.  ~~~~~~~~~
  41.  Normally modules can be installed multiple times, but if bkm_Flags has
  42.  BKMB_SingleMode bit set then this module (RT_NAME and RT_PRI match) can be
  43.  found from ROM only once.
  44.  
  45.  If bkm_Flags has BKMB_ReplaceMode bit set then the ROM is scanned for Resident
  46.  Tag with same name (RT_NAME) and priority (RT_PRI) as in this "module". If
  47.  such resident is found it'll be replaced (overwritten) by module's Resident
  48.  Tag. This feature must be considered as "hackish", because resident tags don't
  49.  always be in ROM as one big chunk, but are split into thousand and one little
  50.  pieces... :-( Additionally there are usually code and data inside Resident Tag
  51.  which has nothing to do with that Tag... :.-((. So, if you'd like like to
  52.  safely(?) replace OS Resident Tags you should use this flag in conjugation
  53.  with BKMB_ExtResBuf.
  54.  
  55.  With this feature you could, for example, replace 'exec.library' resident
  56.  with better one, improve KS3.x 'alert.hook' or improve KS1.3 'bootstrap'...
  57.  It's up to you, Coders...
  58.  
  59.  If you specify BKMB_ExtResBuf flag this module will require it to be installed
  60.  to external Resident Tag buffer created by EXTRESBUF feature of the BlizKick.
  61.  Using this makes only(?) sense with BKMB_ReplaceMode...
  62.  
  63.  It was one shiny day I got up with this *great* idea of "modules". Kickstart
  64.  MapROM tools will never be the same again... ;-)
  65.  
  66.     ENDC
  67.  
  68.  
  69. BKMODULE_ID    EQU    $707A4E75    ; moveq #'z',d0; rts
  70. BKEP_ID        EQU    $4E71        ; nop ;-)
  71.  
  72.     ; bkm_Flags:
  73.  
  74.     BITDEF    BKM,ReplaceMode,0    ; Turn on REPLACE MODE
  75.     BITDEF    BKM,SingleMode,1    ; Do *not* allow same "module" multiple times
  76.     BITDEF    BKM,ExtResBuf,2        ; Require EXTRESBUF for this module
  77. BKMF_ALL EQU    BKMF_ReplaceMode!BKMF_SingleMode!BKMF_ExtResBuf
  78.  
  79.     STRUCTURE bkmodule,0
  80.     ULONG    bkm_ID            ; Must be BKMODULE_ID
  81.     UWORD    bkm_Flags        ; See above
  82.     STRUCT    bkm_ResTag,RT_SIZE    ; Resident Tag (not relocated!)
  83. ;;    LABEL    bkmodule_SIZEOF        ; There's no SIZEOF!
  84.  
  85.  
  86. ;
  87. ; BK_MOD -- Create a simple ResidentTag without AUTOINIT
  88. ;
  89. ; mflags   - "Module" flags, see above.
  90. ; end      - ptr to end of this ResidentTag
  91. ; flags    - ResidentTag flags
  92. ; reqver   - required KS version for this module. This is *NOT*
  93. ;         the ResidentTag version, but required version to use this
  94. ;         module. ResidentTag version will be forced to current
  95. ;         ROM version.
  96. ; type     - type of module (NT_XXXXXX)
  97. ; pri      - priority for this ResidentTag
  98. ; name     - ptr to name of this ResidentTag
  99. ; idstring - ptr to idstring of this ResidentTag
  100. ; init     - ptr to init code
  101.  
  102. ; no-autoinit-module:
  103. BK_MOD    MACRO    *mflags,end,flags<<24+reqver<<16+type<<8+pri,name,idstring,init
  104.     IFGT    NARG-6
  105.     FAIL    !!!! TOO MANY ARGUMENTS TO BK_MOD !!!!
  106.     MEXIT
  107.     ELSE
  108.     IFGT    6-NARG
  109.     FAIL    !!!! TOO FEW ARGUMENTS TO BK_MOD !!!!
  110.     MEXIT
  111.     ENDC
  112.     ENDC
  113.     dc.l    BKMODULE_ID
  114.     dc.w    \1
  115. .mod\@    dc.w    RTC_MATCHWORD
  116.     dc.l    0
  117.     dc.l    ((\2)-.mod\@+1)&-2
  118.     dc.l    (\3)&~(RTF_AUTOINIT<<24)
  119.     dc.l    (\4)-.mod\@
  120.     dc.l    (\5)-.mod\@
  121.     dc.l    (\6)-.mod\@
  122.     ENDM
  123.  
  124.  
  125. ;
  126. ; BK_MODA -- Create a complex ResidentTag with AUTOINIT (library/device/resource?)
  127. ;
  128. ; mflags   - "Module" flags, see above.
  129. ; end      - ptr to end of this ResidentTag
  130. ; flags    - ResidentTag flags
  131. ; reqver   - required KS version for this module. This is *NOT*
  132. ;         the ResidentTag version, but required version to use this
  133. ;         module. ResidentTag version will be forced to current
  134. ;         ROM version.
  135. ; type     - type of module (NT_XXXXXX)
  136. ; pri      - priority for this ResidentTag
  137. ; name     - ptr to name of this ResidentTag
  138. ; idstring - ptr to idstring of this ResidentTag
  139. ; size     - see exec.library/InitResident
  140. ; funcs    - see exec.library/InitResident
  141. ; initstruct - see exec.library/InitResident
  142. ; initfunc - see exec.library/InitResident
  143.  
  144. ; autoinit-module:
  145. BK_MODA    MACRO    *mflags,end,flags<<24+reqver<<16+type<<8+pri,name,idstring,size,funcs,initstruct,initfunc
  146.     IFGT    NARG-9
  147.     FAIL    !!!! TOO MANY ARGUMENTS TO BK_MODA !!!!
  148.     MEXIT
  149.     ELSE
  150.     IFGT    9-NARG
  151.     FAIL    !!!! TOO FEW ARGUMENTS TO BK_MODA !!!!
  152.     MEXIT
  153.     ENDC
  154.     ENDC
  155.     dc.l    BKMODULE_ID
  156.     dc.w    \1
  157. .mod\@    dc.w    RTC_MATCHWORD
  158.     dc.l    0
  159.     dc.l    ((\2)-.mod\@+1)&-2
  160.     dc.l    (\3)!(RTF_AUTOINIT<<24)
  161.     dc.l    (\4)-.mod\@
  162.     dc.l    (\5)-.mod\@
  163.     dc.l    .mod2\@-.mod\@
  164. .mod2\@    dc.l    \6
  165.     dc.l    (\7)-.mod\@
  166.     dc.l    (\8)-.mod\@
  167.     dc.l    (\9)-.mod\@
  168.     ENDM
  169.  
  170.  
  171. ;
  172. ; BK_PTC -- Create a header for BlizKick external patch
  173. ;
  174. ;   Notes
  175. ;   ~~~~~
  176. ; Code is run with following incoming parameters:
  177. ;
  178. ; a0=ptr to ROM start (buffer)    eg. $1DE087B8
  179. ; a1=ptr to ROM start (ROM)    eg. $00F80000 (do *not* access!)
  180. ; d0=ROM lenght in bytes    eg. $00080000
  181. ; a2=ptr to _FindResident routine (will search ROM buffer for resident tag):
  182. ;    CALL: jsr (a2)
  183. ;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to resident name
  184. ;     OUT: d0=ptr to resident (buf) or NULL
  185. ; a3=ptr to _InstallModule routine (can be used to plant a "module"):
  186. ;    CALL: jsr (a3)
  187. ;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to module, d6=dosbase
  188. ;     OUT: d0=success
  189. ; a4=ptr to _Printf routine (will dump some silly things (errormsg?) to stdout ;-)
  190. ;    CALL: jsr (a4)
  191. ;      IN: a0=FmtString, a1=Array (may be 0), d6=dosbase
  192. ;     OUT: -
  193. ; d6=dosbase, a6=execbase
  194. ;
  195. ; Code should return:
  196. ;
  197. ; d0=true if succeeded, false if failed.
  198. ; d1-d7/a0-a6 can be trashed. a7 *must* be preserved! ;-)
  199. ;
  200. ; Code doesn't need to worry about cache flushing after it has done its
  201. ; modifications. (Except if the code uses self-modifying (!?) code...)
  202. ; If the patch code requires some new KS (3.x) features you *must* test for
  203. ; approriate KS version!! If patch code is run you can assume that you're
  204. ; running on at least AmigaOS 2.0 (V36).
  205. ;
  206. ; Please, be as fast as possible because user might want to add *several*
  207. ; patches!
  208. ;
  209. ; The macro is used like this:
  210. ;
  211. ;    SECTION    PATCH,CODE
  212. ;
  213. ;_SEGSTART_DUMMY:
  214. ;
  215. ;    BK_PTC
  216. ;
  217. ;patchcode:
  218. ;    cmp.w    #37,($C,A0)    ; This patch requires V37 ROM (KS 2.04) or better...
  219. ;    blo.b    .fail
  220. ;
  221. ;    move.l    #$xxxxxxxx,d1    ; Search for (xxxxxxxx,yyyyyyyy,zzzzzzzz):
  222. ;.find    subq.l    #2,d0
  223. ;    beq.b    .fail
  224. ;    addq.l    #2,a0
  225. ;    cmp.l    (a0),d1
  226. ;    bne.b    .find
  227. ;    cmp.l    #$yyyyyyyy,(4,a0)
  228. ;    bne.b    .find
  229. ;    cmp.l    #$zzzzzzzz,(8,a0)
  230. ;    bne.b    .find
  231. ;    bra.b    .found
  232. ;
  233. ;.fail    moveq    #0,d0
  234. ;    rts
  235. ;
  236. ;.found    movem.l    d2-d7/a2-a6,-(sp)
  237. ;
  238. ;    do the patching...
  239. ;    ...etc...
  240. ;
  241. ;    movem.l    (sp)+,d2-d7/a2-a6
  242. ;    moveq    #1,d0
  243. ;    rts
  244. ;
  245.  
  246. ; external patch:
  247. BK_PTC    MACRO
  248.     IFGT    NARG
  249.     FAIL    !!!! BK_PTC DOES NOT TAKE ANY ARGUMENTS !!!!
  250.     MEXIT
  251.     ENDC
  252.     dc.l    BKMODULE_ID
  253.     dc.w    0,BKEP_ID
  254.     ENDM
  255.  
  256.  
  257. ; Following macros can be used to create function tables for devices, libraries
  258. ; and resources:
  259.  
  260. BK_INITFUNCS    MACRO    *label
  261.     IFGT    NARG-1
  262.     FAIL    !!!! TOO MANY ARGUMENTS TO BK_INITFUNCS !!!!
  263.     MEXIT
  264.     ELSE
  265.     IFGT    1-NARG
  266.     FAIL    !!!! TOO FEW ARGUMENTS TO BK_INITFUNCS !!!!
  267.     MEXIT
  268.     ENDC
  269.     ENDC
  270.     CNOP    0,2
  271. \1
  272. _BKM_FB_GLOBAL\@
  273.     dc.w    -1
  274. .BKM_FUNCBASE    EQU    *-2
  275.     ENDM
  276.  
  277. BK_FUNC    MACRO    *funclabel
  278.     IFGT    NARG-1
  279.     FAIL    !!!! TOO MANY ARGUMENTS TO BK_FUNC !!!!
  280.     MEXIT
  281.     ELSE
  282.     IFGT    1-NARG
  283.     FAIL    !!!! TOO FEW ARGUMENTS TO BK_FUNC !!!!
  284.     MEXIT
  285.     ENDC
  286.     ENDC
  287.     dc.w    (\1)-.BKM_FUNCBASE
  288.     ENDM
  289.  
  290. BK_ENDFUNCS    MACRO
  291.     IFGT    NARG
  292.     FAIL    !!!! BK_ENDFUNCS DOES NOT TAKE ANY ARGUMENTS !!!!
  293.     MEXIT
  294.     ENDC
  295.     dc.w    -1
  296.     ENDM
  297.  
  298.     ENDC    ; BLIZK